package cn.edu.sdjzu.xg.kcsj.controller.basic;

import cn.edu.sdjzu.xg.kcsj.domain.CourseArrangement;
import cn.edu.sdjzu.xg.kcsj.service.CourseArrangementService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import util.JSONUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/insertCourseArrangement.ctl")
public class InsertCourseArrangementController extends HttpServlet {
    @Override
    protected void doPost (HttpServletRequest req,HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        String student_json = JSONUtil.getJSON(req);
        JSONObject respMessage_jsonObj = new JSONObject ();
        CourseArrangement courseArrangement = JSON.parseObject(student_json, CourseArrangement.class);
        boolean add = false;
        try {
            add = CourseArrangementService.getInstance ().add(courseArrangement);
        } catch (SQLException e) {
            respMessage_jsonObj.put ("message","sjk have exception");
            e.printStackTrace ();
        }
        if (add){
            respMessage_jsonObj.put ("message","add yes");
        }else {
            respMessage_jsonObj.put("message","add no");
        }
        try {
            resp.getWriter ().println (respMessage_jsonObj);
        } catch (IOException e) {
            e.printStackTrace ();
        }
    }
}
